{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 4.7 \u8fed\u4ee3\u5668\u5207\u7247\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u95ee\u9898\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u60f3\u5f97\u5230\u4e00\u4e2a\u7531\u8fed\u4ee3\u5668\u751f\u6210\u7684\u5207\u7247\u5bf9\u8c61\uff0c\u4f46\u662f\u6807\u51c6\u5207\u7247\u64cd\u4f5c\u5e76\u4e0d\u80fd\u505a\u5230\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u89e3\u51b3\u65b9\u6848\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u51fd\u6570 itertools.islice() \u6b63\u597d\u9002\u7528\u4e8e\u5728\u8fed\u4ee3\u5668\u548c\u751f\u6210\u5668\u4e0a\u505a\u5207\u7247\u64cd\u4f5c\u3002\u6bd4\u5982\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "def count(n):\n    while True:\n        yield n\n        n += 1\nc = count(0)\nc[10:20]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# Now using islice()\nimport itertools\nfor x in itertools.islice(c, 10, 20):\n    print(x)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u8ba8\u8bba\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8fed\u4ee3\u5668\u548c\u751f\u6210\u5668\u4e0d\u80fd\u4f7f\u7528\u6807\u51c6\u7684\u5207\u7247\u64cd\u4f5c\uff0c\u56e0\u4e3a\u5b83\u4eec\u7684\u957f\u5ea6\u4e8b\u5148\u6211\u4eec\u5e76\u4e0d\u77e5\u9053(\u5e76\u4e14\u4e5f\u6ca1\u6709\u5b9e\u73b0\u7d22\u5f15)\u3002\n\u51fd\u6570 islice() \u8fd4\u56de\u4e00\u4e2a\u53ef\u4ee5\u751f\u6210\u6307\u5b9a\u5143\u7d20\u7684\u8fed\u4ee3\u5668\uff0c\u5b83\u901a\u8fc7\u904d\u5386\u5e76\u4e22\u5f03\u76f4\u5230\u5207\u7247\u5f00\u59cb\u7d22\u5f15\u4f4d\u7f6e\u7684\u6240\u6709\u5143\u7d20\u3002\n\u7136\u540e\u624d\u5f00\u59cb\u4e00\u4e2a\u4e2a\u7684\u8fd4\u56de\u5143\u7d20\uff0c\u5e76\u76f4\u5230\u5207\u7247\u7ed3\u675f\u7d22\u5f15\u4f4d\u7f6e\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8fd9\u91cc\u8981\u7740\u91cd\u5f3a\u8c03\u7684\u4e00\u70b9\u662f islice() \u4f1a\u6d88\u8017\u6389\u4f20\u5165\u7684\u8fed\u4ee3\u5668\u4e2d\u7684\u6570\u636e\u3002\n\u5fc5\u987b\u8003\u8651\u5230\u8fed\u4ee3\u5668\u662f\u4e0d\u53ef\u9006\u7684\u8fd9\u4e2a\u4e8b\u5b9e\u3002\n\u6240\u4ee5\u5982\u679c\u4f60\u9700\u8981\u4e4b\u540e\u518d\u6b21\u8bbf\u95ee\u8fd9\u4e2a\u8fed\u4ee3\u5668\u7684\u8bdd\uff0c\u90a3\u4f60\u5c31\u5f97\u5148\u5c06\u5b83\u91cc\u9762\u7684\u6570\u636e\u653e\u5165\u4e00\u4e2a\u5217\u8868\u4e2d\u3002"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.1"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": true,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}